package com.sip.dbadapter.dao.domain;

import java.io.Serializable;
import java.util.HashSet;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;
import javax.persistence.PrimaryKeyJoinColumn;
import javax.persistence.Table;

/**
 *
 */
@Entity
@Table(name = "SCAN_TYPE_REST")
public class ScanTypeRest implements Serializable {

    private static final long serialVersionUID = 1L;

    public Long scanTypeId;

    private String methodUrl;

    private String methodAction;
    
    private String resourceBase;

    private Set<ConsumeTemplate> consumeTemplateSet = new HashSet<ConsumeTemplate>();

    private Set<MediaType> mediaTypeSet = new HashSet<MediaType>();

    private ApiDefinition apiDefinition;

    public ScanTypeRest() {

        scanTypeId = Long.valueOf(0);
    }

    /*
     * @GenericGenerator(name = "generator", strategy = "foreign", parameters = @Parameter(name = "property", value =
     * "apiDefinition"))
     * @Id
     * @GeneratedValue(generator = "generator")
     * @Column(name = "API_ID_REST", unique = true, nullable = false)
     */
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "API_ID_REST", unique = true, nullable = false)
    public Long getScanTypeId() {

        return scanTypeId;
    }

    @Column(name = "METHOD_URL")
    public String getMethodUrl() {

        return methodUrl;
    }

    @Column(name = "METHOD_ACTION")
    public String getMethodAction() {

        return methodAction;
    }
    

    @Column(name = "RESOURCE_BASE")
	public String getResourceBase() {
		return resourceBase;
	}

    @OneToOne(fetch = FetchType.LAZY)
    @PrimaryKeyJoinColumn
    public ApiDefinition getApiDefinition() {

        return apiDefinition;
    }

    @OneToMany(fetch = FetchType.EAGER, cascade = CascadeType.ALL, mappedBy = "scanTypeRest")
    public Set<ConsumeTemplate> getConsumeTemplateSet() {

        return consumeTemplateSet;
    }

    @OneToMany(fetch = FetchType.LAZY, cascade = CascadeType.ALL, mappedBy = "scanTypeRest")
    public Set<MediaType> getMediaTypeSet() {

        return mediaTypeSet;
    }

    public void setMediaTypeSet(Set<MediaType> mediaTypeSet) {

        this.mediaTypeSet = mediaTypeSet;
    }

    public void setMethodUrl(String methodUrl) {

        this.methodUrl = methodUrl;
    }
    

	public void setResourceBase(final String resourceBase) {
		
		this.resourceBase = resourceBase;
	}



    public void setMethodAction(String methodAction) {

        this.methodAction = methodAction;
    }

    public void setScanTypeId(Long scanTypeId) {

        this.scanTypeId = scanTypeId;
    }

    public void setApiDefinition(ApiDefinition apiDefinition) {

        this.apiDefinition = apiDefinition;
    }

    public void setConsumeTemplateSet(Set<ConsumeTemplate> consumeTemplateSet) {

        this.consumeTemplateSet = consumeTemplateSet;
    }

    @Override
    public int hashCode() {

        int result = 0;
        result = (int) (31 * result + scanTypeId);
        result = 31 * result + (methodUrl != null ? methodUrl.hashCode() : 0);

        return result;
    }

    @Override
    public boolean equals(Object other) {

        if (this == other)
            return true;

        if (other == null || (this.getClass() != other.getClass())) {
            return false;
        }

        ScanTypeRest scanType = (ScanTypeRest) other;
        return (this.scanTypeId == scanType.scanTypeId) && (this.methodUrl != null && methodUrl.equals(scanType.methodUrl));

    }

}
